
#include "RtBase.h"
#include "RtConfigInitFile.h"

extern unsigned char get_string_param(char* group, char* item_key, char* item_value, unsigned long len);
extern char* get_iwlab_home_dir();
extern void set_iwlab_home_env(char* home_env);

CRtConfigInitFile::CRtConfigInitFile()
{
}

CRtConfigInitFile::~CRtConfigInitFile()
{
}

RtResult CRtConfigInitFile::InitWithFileName(const CRtString &aFileName)
{
	return RT_OK;
}

int CRtConfigInitFile::
GetIntParam(const CRtString &aGroup,  const CRtString &aKey, int aDefault)
{
	char str_value[256];
	if (get_string_param(
			const_cast<char*>(aGroup.c_str()), 
			const_cast<char*>(aKey.c_str()), 
			str_value, 
			sizeof(str_value)))
	{
		int i;
		sscanf(str_value, "%d", &i);
		return i;
	}
	else
		return aDefault;
}

DWORD CRtConfigInitFile::
GetDwordParam(const CRtString &aGroup, const CRtString &aKey, DWORD aDefault)
{
	char str_value[256];
	if (get_string_param(
			const_cast<char*>(aGroup.c_str()), 
			const_cast<char*>(aKey.c_str()), 
			str_value, 
			sizeof(str_value)))
	{
		DWORD i;
		sscanf(str_value, "%u", &i);
		return i;
	}
	else
		return aDefault;
}

WORD CRtConfigInitFile::
GetWordParam(const CRtString &aGroup, const CRtString &aKey, WORD aDefault)
{
	char str_value[256];
	if (get_string_param(
			const_cast<char*>(aGroup.c_str()), 
			const_cast<char*>(aKey.c_str()), 
			str_value, 
			sizeof(str_value)))
	{
		WORD i;
		sscanf(str_value, "%hu", &i);
		return i;
	}
	else
		return aDefault;
}

CRtString CRtConfigInitFile::
GetStringParam(const CRtString &aGroup, const CRtString &aKey, CRtString aDefault)
{
	char str_value[256];
	if (get_string_param(
			const_cast<char*>(aGroup.c_str()), 
			const_cast<char*>(aKey.c_str()), 
			str_value, 
			sizeof(str_value)))
	{
		return CRtString(str_value);
	}
	else
		return aDefault;
}

BOOL CRtConfigInitFile::
GetBoolParam(const CRtString &aGroup, const CRtString &aKey, BOOL aDefault)
{
	char str_value[256];
	if (get_string_param(
			const_cast<char*>(aGroup.c_str()), 
			const_cast<char*>(aKey.c_str()), 
			str_value, 
			sizeof(str_value)))
	{
		return strcasecmp(str_value, "TRUE") == 0;
	}
	else
		return aDefault;
}

